/**************************************
This program graphs the results from 02.regs_figure5 to generate Figure 5



Author: Kevin Stange
Date: 06/24/2021
Update: 6/24/2021
Update: 9/28/2021 included new disclosed results
Update: 5/8/2022 included new disclosed results

Important note: need to set cd to file location: 
(e.g. .\Github\footestange_biaspaper\analysis_progs)
*************************************/

version 16
include "./config.do"
cap log close
log using "./06.03.bias_graphs_$date.log", replace
set more off 
set scheme s1mono 

/* Analysis of Top School Bias */
import delimited "$supportdir/bias_scatter_barrons_byyear_2023-08-23.csv", clear 

tab state 

label def statel 8 "CO" 36 "NY" 39 "OH" 42 "PA" 48 "TX" 13 "GA" 27 "MN" 29 "MO" 51 "VA"
label val state statel
tab grad_year state 

tab grad_year state  [fw = out_n]

tab grad_year state  [fw = missing_n]

* Need to drop 2001 and 2002 cohorts in PA. They are really small for some reason



**** TABLE 4 *****************

* First including all cohorts
table year_post state [aw=out_n], c(mean bias) col row 

table year_post state [aw=missing_n], c(mean missing_diff) col row 

* Excluding grad years 2001 and 2002
table year_post state if grad_year >= 2003 [aw=out_n], c(mean bias) col row 

table year_post state if grad_year >= 2003 [aw=missing_n], c(mean missing_diff) col row 

/********************************************
Creating T-statistics
********************************************/

gen se_bias = sqrt(se_in^2 + se_out^2) 

gen t_stat = bias/se_bias

gen sig = (t_stat > 1.96)
#delimit ; 
twoway (scatter bias missing_diff if state==8 & grad_year >= 2003, mc(green)) 
		(scatter bias missing_diff if state==36 & grad_year >= 2003, mc(blue)) 
		(scatter bias missing_diff if state==39 & grad_year >= 2003 )  
		(scatter bias missing_diff if state==42 & grad_year >= 2003) 
		(scatter bias missing_diff if state==48 & grad_year >= 2003, mc(red)) 
		(scatter bias missing_diff if state==13 & grad_year >=2003, mc(orange))
		(scatter bias missing_diff if state==27 & grad_year >=2003, mc(lime))
		(scatter bias missing_diff if state==29 & grad_year >=2003, mc(cranberry))
		(scatter bias missing_diff if state==51 & grad_year >=2003, mc(gold)), 
		legend(label(1 "CO") label(2 "NY") label(3 "OH") label(4 "PA") label(5 "TX")
			label(6 "GA") label(7 "MN") label(8 "MO") label(9 "VA") rows(2) )
		ytitle("Bias") xtitle("Difference in Rate of No In-State Earnings") ;
	 	
graph export "$resultsdir/betas_by_state_scatter_$date.png", replace  ;

end
/***************************************************
Reg with new states and without 
***************************************************/

reg bias missing_diff i.year_post i.state i.grad_year [aw=out_n], robust ;

 reg bias missing_diff i.year_post i.state i.grad_year [aw=out_n] if state == 8 | state==36 | state ==39 | state == 42 | state == 39 | state == 48, robust ;


	end
twoway (scatter  missing_diff bias if state==8 & grad_year >= 2003, mc(green))  ///
		(scatter missing_diff bias if state==36 & grad_year >= 2003, mc(blue)) ///
		(scatter missing_diff bias if state==39 & grad_year >= 2003 )  ///
		(scatter missing_diff bias if state==42 & grad_year >= 2003) ///	
		(scatter missing_diff bias if state==48 & grad_year >= 2003, mc(red)) , ///
		legend(label(1 "CO") label(2 "NY") label(3 "OH") label(4 "PA") label(5 "TX") rows(1) ) ///
		ytitle("Difference in Rate of No In-State Earnings") xtitle("Bias")
		
graph export "$graphdir/betas_by_state_scatter_flipped.png", replace  
